﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    public class XVerticalAlignmentConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            string strAlign = valueNode.Attributes["Value"];
            if (!string.IsNullOrEmpty(strAlign))
            {
                System.Windows.VerticalAlignment verticalAlignment = (System.Windows.VerticalAlignment)Enum.Parse(typeof(System.Windows.VerticalAlignment), strAlign);
                return verticalAlignment;
            }
            return null;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            System.Windows.VerticalAlignment verticalAlignment = (System.Windows.VerticalAlignment)Enum.Parse(typeof(System.Windows.VerticalAlignment), System.Convert.ToString(value));
            Metadata.ValueNode valueNode = new Metadata.ValueNode("LegendVerticalAlignment");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", verticalAlignment.ToString());
            return valueNode;
        }
    }
}
